﻿<template>
    <div class="UsingWireropeDetail">
        <MyDialog :model-value="true" :type="DialogType.C3" :title="title" @close="onClose">
            <el-form ref="UsingWireropeDetailFormRef" label-width="110" :model="thisData" :rules="rules">
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="钢丝绳编码" prop="code">
                            <el-input v-model="thisData.code" disabled maxlength="50">
                                <template #append v-if="!isSee && !isEdit">
                                    <el-button @click="onOpenStockSelect">
                                        <el-icon>
                                            <Search />
                                        </el-icon>
                                    </el-button>
                                </template>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="钢丝绳名称" prop="name">
                            <el-input v-model="thisData.name" maxlength="200" :disabled="isSee"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="规格型号" prop="guiGe">
                            <el-input v-model="thisData.guiGe" :disabled="true" maxlength="200"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="直径" prop="diameter">
                            <InputNumber v-model="thisData.diameter" :disabled="true" append="mm"></InputNumber>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="公称捻距" prop="nianJu">
                            <InputNumber v-model="thisData.nianJu" :disabled="true" append="mm"></InputNumber>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="长度" prop="lengthNum">
                            <InputNumber v-model="thisData.lengthNum" :disabled="true" append="m"></InputNumber>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="绳子条数" prop="cnt">
                            <InputNumber v-model="thisData.cnt" :precision="0" :disabled="true" append="根"></InputNumber>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="抗拉强度" prop="mpaID">
                            <DataSelect table="Mpa" class="w-100" v-model:id="thisData.mpaID" v-model:name="thisData.mpaName" :disabled="true"></DataSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="表面状态" prop="surfaceStatusID">
                            <DataSelect table="SurfaceStatus" class="w-100" v-model:id="thisData.surfaceStatusID" v-model:name="thisData.surfaceStatusName" :disabled="true"></DataSelect>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="捻制类型" prop="twistingTypeID">
                            <DataSelect table="TwistingType" class="w-100" v-model:id="thisData.twistingTypeID" v-model:name="thisData.twistingTypeName" :disabled="true"></DataSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="矿山" prop="departmentID">
                            <DataSelect table="Department" class="w-100" :filter="{ _Type: Enums.Department_Type.矿山 }" v-model:id="thisData.departmentID" :disabled="isSee"></DataSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="安装日期" prop="installDate">
                            <el-date-picker class="w-100" :disabled-date="installDateDisabledDate" v-model="thisData.installDate" type="date" :disabled="isSee" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="安装长度" prop="installLengthNum">
                            <InputNumber v-model="thisData.installLengthNum" append="m" :disabled="isSee"></InputNumber>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="安装地点" prop="installAddressID">
                            <DataSelect ref="installAddressIDSelect" :isLoadingData="false" table="InstallAddress" class="w-100" label="addressInfo" v-model:id="thisData.installAddressID" v-model:name="thisData.installAddressName" :disabled="isSee"></DataSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="提升机类型" prop="hoisterID">
                            <DataSelect ref="hoisterIDSelect" :isLoadingData="false" table="Hoister" class="w-100" v-model:id="thisData.hoisterID" v-model:name="thisData.hoisterName" :disabled="isSee" @change="hoisterChange"></DataSelect>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="提升机用途" prop="hoisterUsageID">
                            <DataSelect ref="HoisterUsageRef" :isLoadingData="false" table="HoisterUsage" class="w-100" :filter="{ _HoisterID: thisData.hoisterID }" v-model:id="thisData.hoisterUsageID" v-model:name="thisData.hoisterUsageName" :disabled="isSee"></DataSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="钢丝绳类型" prop="wireropeTypeID">
                            <DataSelect ref="WireropeTypeRef" :isLoadingData="false" table="WireropeType" class="w-100" :filter="{ _HoisterID: thisData.hoisterID }" v-model:id="thisData.wireropeTypeID" v-model:name="thisData.wireropeTypeName" :disabled="isSee"></DataSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="主要负责人" prop="linkUser" v-if="!isSee">
                            <el-input v-model="thisData.linkUser" maxlength="50"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row v-if="!isSee">
                    <el-col :span="8">
                        <el-form-item label="负责人电话" prop="linkPhone">
                            <el-input v-model="thisData.linkPhone" maxlength="20"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="备注" prop="remark">
                            <el-input v-model="thisData.remark" maxlength="500"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="视频链接" prop="remark">
                            <el-input v-model="thisData.videoUrl" maxlength="500"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row v-if="!isSee">
                    <el-col :span="8">
                        <el-form-item label="出库日期" prop="outStockDate">
                            <el-date-picker class="w-100" :disabled-date="installDateDisabledDate" v-model="thisData.outStockDate" type="date" :disabled="isEdit" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="下次检测日期" prop="nextCheckDate">
                            <el-date-picker class="w-100" v-model="thisData.nextCheckDate" type="date" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8"> </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="挂绳前试验报告" prop="laNiu_Files">
                            <ButtonImage v-model="thisData.laNiu_FilesList" appendToBody :readonly="isSee" type="warning" :text="isSee ? '查看' : '上传'"></ButtonImage>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="挂绳前无损报告" prop="qianWuSun_Files">
                            <ButtonImage v-model="thisData.qianWuSun_FilesList" appendToBody :readonly="isSee" type="warning" :text="isSee ? '查看' : '上传'"></ButtonImage>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="挂绳后无损报告" prop="houWuSun_Files">
                            <ButtonImage v-model="thisData.houWuSun_FilesList" appendToBody :readonly="isSee" type="warning" :text="isSee ? '查看' : '上传'"></ButtonImage>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row>
                    <el-col :span="8">
                        <el-form-item label="出厂报告" prop="chuChang_Files">
                            <ButtonImage v-model="thisData.chuChang_FilesList" appendToBody :readonly="isSee" type="warning" :text="isSee ? '查看' : '上传'"></ButtonImage>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="验收报告" prop="yanShou_Files">
                            <ButtonImage v-model="thisData.yanShou_FilesList" appendToBody :readonly="isSee" type="warning" :text="isSee ? '查看' : '上传'"></ButtonImage>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="倒卷检测报告" prop="jianCe_Files">
                            <ButtonImage v-model="thisData.jianCe_FilesList" appendToBody :readonly="isSee" type="warning" :text="isSee ? '查看' : '上传'"></ButtonImage>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="附件" prop="attr_Files">
                            <ButtonImage v-model="thisData.attr_FilesList" appendToBody :readonly="isSee" type="warning" :text="isSee ? '查看' : '上传'"></ButtonImage>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>

            <el-tabs v-model="activeName" type="border-card" v-if="isSee">
                <el-tab-pane label="入库信息" name="入库信息">
                    <DataTable ref="billDataTableRef" divHeight="360px" :data="thisData.billModelList" :hasTop="false" :hasPager="false" :hasCheckbox="false">
                        <vxe-column title="入库单号" min-width="120" show-overflow>
                            <template #default="{ row }">
                                {{ row.code || "-" }}
                            </template>
                        </vxe-column>

                        <!-- <vxe-column title="出入库类型" min-width="120" show-overflow>
                            <template #default="{ row }">
                                <span :class="Enums.Bill_InOutType.Get(row.inOutType).color">{{ Enums.Bill_InOutType.Get(row.inOutType).text }}</span>
                            </template>
                        </vxe-column> -->

                        <vxe-column title="入库类型" min-width="120" show-overflow>
                            <template #default="{ row }">
                                {{ row.operType_Name || "-" }}
                            </template>
                        </vxe-column>

                        <vxe-column title="状态" min-width="120" show-overflow>
                            <template #default="{ row }">
                                <span :class="Enums.Bill_Status.Get(row.status).color">{{ Enums.Bill_Status.Get(row.status).text }}</span>
                            </template>
                        </vxe-column>

                        <vxe-column title="申请人" min-width="120" show-overflow>
                            <template #default="{ row }">
                                {{ row.applyUserName || "-" }}
                            </template>
                        </vxe-column>

                        <vxe-column title="申请时间" min-width="120" show-overflow>
                            <template #default="{ row }">
                                {{ Gx.YMD(row.createDate) }}
                            </template>
                        </vxe-column>

                        <vxe-column title="验收人" min-width="120" show-overflow>
                            <template #default="{ row }">
                                {{ row.confirmUserName || "-" }}
                            </template>
                        </vxe-column>

                        <vxe-column title="验收时间" min-width="120" show-overflow>
                            <template #default="{ row }">
                                {{ Gx.YMD(row.confirmDate) }}
                            </template>
                        </vxe-column>

                        <vxe-column title="入库备注" min-width="120" show-overflow>
                            <template #default="{ row }">
                                {{ row.remark || "-" }}
                            </template>
                        </vxe-column>
                    </DataTable>
                </el-tab-pane>

                <el-tab-pane label="备绳维保" name="备绳维保">
                    <DataTable ref="keepDataTableRef" divHeight="360px" :data="thisData.stockWireropeKeepModelList" :hasTop="false" :hasPager="false" :hasCheckbox="false">
                        <vxe-column title="实施单位">
                            <template #default="{ row }" min-width="120" show-overflow>
                                {{ row.companyName || "-" }}
                            </template>
                        </vxe-column>

                        <vxe-column title="实施人员" min-width="120" show-overflow>
                            <template #default="{ row }">
                                {{ row.userName || "-" }}
                            </template>
                        </vxe-column>

                        <vxe-column title="实施日期" min-width="120" show-overflow>
                            <template #default="{ row }">
                                {{ Gx.YMD(row.doDate) }}
                            </template>
                        </vxe-column>

                        <vxe-column title="实施照片" min-width="120" show-overflow>
                            <template #default="{ row }">
                                <ButtonImage v-model="row.pic_ImgsList" appendToBody readonly type="warning" text="查看"></ButtonImage>
                            </template>
                        </vxe-column>

                        <vxe-column title="备注" min-width="120" show-overflow>
                            <template #default="{ row }">
                                {{ row.remark || "-" }}
                            </template>
                        </vxe-column>

                        <vxe-column title="状态" min-width="120" show-overflow>
                            <template #default="{ row }">
                                <span :class="Enums.StockWireropeKeep_Status.Get(row.status).color">{{ Enums.StockWireropeKeep_Status.Get(row.status).text }}</span>
                            </template>
                        </vxe-column>

                        <vxe-column title="操作" min-width="120" fixed="right">
                            <template #default="{ row }">
                                <el-button type="warning" @click="onShowDetail(row, '备绳维保')">详情</el-button>
                            </template>
                        </vxe-column>
                    </DataTable>
                </el-tab-pane>

                <el-tab-pane label="安装信息" name="安装信息">
                    <DataTable ref="installDataTableRef" divHeight="360px" :data="thisData.installModelList" :hasTop="false" :hasPager="false" :hasCheckbox="false">
                        <vxe-column title="创建人" min-width="120" show-overflow>
                            <template #default="{ row }">
                                {{ row.createUserName || "-" }}
                            </template>
                        </vxe-column>

                        <vxe-column title="安装日期" min-width="120" show-overflow>
                            <template #default="{ row }">
                                {{ Gx.YMD(row.installTime) }}
                            </template>
                        </vxe-column>

                        <vxe-column title="换绳原因" min-width="120" show-overflow>
                            <template #default="{ row }">
                                {{ row.reason || "-" }}
                            </template>
                        </vxe-column>

                        <vxe-column title="备注" min-width="120" show-overflow>
                            <template #default="{ row }">
                                {{ row.remark || "-" }}
                            </template>
                        </vxe-column>

                        <vxe-column title="类型" min-width="120" show-overflow>
                            <template #default="{ row }">
                                <span :class="Enums.Install_Type.Get(row.type).color">{{ Enums.Install_Type.Get(row.type).text }}</span>
                            </template>
                        </vxe-column>

                        <!-- <vxe-column title="操作" min-width="120" fixed="right">
                            <template #default="{ row }">
                                <el-button type="warning" @click="onShowDetail(row, '安装信息')">详情</el-button>
                            </template>
                        </vxe-column> -->
                    </DataTable>
                </el-tab-pane>

                <el-tab-pane label="在用维保" name="在用维保">
                    <DataTable ref="usingDataTableRef" divHeight="360px" :data="thisData.usingWireropeKeepModelList" :hasTop="false" :hasPager="false" :hasCheckbox="false">
                        <vxe-column title="维保类型" min-width="120" show-overflow>
                            <template #default="{ row }">
                                {{ row.wireropeKeepType_Name || "-" }}
                            </template>
                        </vxe-column>

                        <vxe-column title="实施对象" min-width="120" show-overflow>
                            <template #default="{ row }">
                                {{ row.doPosition || "-" }}
                            </template>
                        </vxe-column>

                        <vxe-column title="实施单位" min-width="120" show-overflow>
                            <template #default="{ row }">
                                {{ row.companyName || "-" }}
                            </template>
                        </vxe-column>

                        <vxe-column title="实施人员" min-width="120" show-overflow>
                            <template #default="{ row }">
                                {{ row.userName || "-" }}
                            </template>
                        </vxe-column>

                        <vxe-column title="实施日期" min-width="120" show-overflow>
                            <template #default="{ row }">
                                {{ Gx.YMD(row.doDate) }}
                            </template>
                        </vxe-column>

                        <vxe-column title="实施照片" min-width="120" show-overflow>
                            <template #default="{ row }">
                                <ButtonImage v-model="row.pic_ImgsList" appendToBody readonly type="warning" text="查看"></ButtonImage>
                            </template>
                        </vxe-column>

                        <vxe-column title="备注" min-width="120" show-overflow>
                            <template #default="{ row }">
                                {{ row.remark || "-" }}
                            </template>
                        </vxe-column>

                        <!-- <vxe-column title="状态" min-width="120" show-overflow>
                            <template #default="{ row }">
                                <span :class="Enums.StockWireropeKeep_Status.Get(row.status).color">{{ Enums.StockWireropeKeep_Status.Get(row.status).text }}</span>
                            </template>
                        </vxe-column> -->

                        <vxe-column title="操作" min-width="120" fixed="right">
                            <template #default="{ row }">
                                <el-button type="warning" @click="onShowDetail(row, '在用维保')">详情</el-button>
                            </template>
                        </vxe-column>
                    </DataTable>
                </el-tab-pane>

                <el-tab-pane label="在用检测" name="在用检测">
                    <DataTable ref="checkDataTableRef" divHeight="360px" :data="thisData.checkWireropeModelList" :hasTop="false" :hasPager="false" :hasCheckbox="false">
                        <vxe-column title="检测单位" min-width="200" show-overflow>
                            <template #default="{ row }">
                                {{ row.checkUnit || "-" }}
                            </template>
                        </vxe-column>

                        <vxe-column title="检测人员" min-width="120" show-overflow>
                            <template #default="{ row }">
                                {{ row.checkUserName || "-" }}
                            </template>
                        </vxe-column>

                        <vxe-column title="检测日期" min-width="120" show-overflow>
                            <template #default="{ row }">
                                {{ Gx.YMD(row.checkDate) }}
                            </template>
                        </vxe-column>

                        <vxe-column title="状态" min-width="120" show-overflow>
                            <template #default="{ row }">
                                <span :class="Enums.check_Status.Get(row.status).color">{{ Enums.check_Status.Get(row.status).text }}</span>
                            </template>
                        </vxe-column>

                        <vxe-column title="操作" min-width="120" fixed="right">
                            <template #default="{ row }">
                                <el-button type="warning" @click="onShowDetail(row, '在用检测')">详情</el-button>
                            </template>
                        </vxe-column>
                    </DataTable>
                </el-tab-pane>

                <el-tab-pane label="作废信息" name="作废信息">
                    <DataTable ref="zuoFeiDataTableRef" divHeight="360px" :data="thisData.zuoFeiModelList" :hasTop="false" :hasPager="false" :hasCheckbox="false">
                        <vxe-column title="创建人" min-width="120" show-overflow>
                            <template #default="{ row }">
                                {{ row.createUserName || "-" }}
                            </template>
                        </vxe-column>

                        <vxe-column title="作废日期" min-width="120" show-overflow>
                            <template #default="{ row }">
                                {{ Gx.YMD(row.zuoFeiTime) }}
                            </template>
                        </vxe-column>

                        <vxe-column title="安全运行时长" min-width="120" show-overflow>
                            <template #default="{ row }">{{ Gx.DateDiff(DatePart.Day, thisData.installDate, row.zuoFeiTime) }}天 </template>
                        </vxe-column>

                        <vxe-column title="换绳原因" min-width="120" show-overflow>
                            <template #default="{ row }">
                                {{ row.reason || "-" }}
                            </template>
                        </vxe-column>

                        <vxe-column title="备注" min-width="120" show-overflow>
                            <template #default="{ row }">
                                {{ row.remark || "-" }}
                            </template>
                        </vxe-column>

                        <vxe-column title="操作" min-width="120" fixed="right">
                            <template #default="{ row }">
                                <el-button type="warning" @click="onShowDetail(row, '作废信息')">详情</el-button>
                                <el-button type="warning" @click="onShowDetail(row, '作废管理')">专家评估</el-button>
                            </template>
                        </vxe-column>
                    </DataTable>
                </el-tab-pane>
            </el-tabs>
            <!-- 钢丝绳库存 -->
            <StockSelect v-if="isShowStockSelect" :hasCheckbox="false" :hasRadio="true" @close="onCloseStockSelect" :defaultFilter="{ _IsOut: false, _IsSelect: true }"></StockSelect>
            <!-- 备绳维保详情 -->
            <StockWireropeKeepDetail ref="StockWireropeKeepDetailRef" v-if="isShowStockWireropeKeepDetail" @close="isShowStockWireropeKeepDetail = false"></StockWireropeKeepDetail>
            <!-- 在用绳维保详情 -->
            <UsingWireropeKeepDetail ref="UsingWireropeKeepDetailRef" v-if="isShowUsingWireropeKeep" @close="isShowUsingWireropeKeep = false"></UsingWireropeKeepDetail>
            <!-- 在用绳检测详情 -->
            <CheckWireropeDetail ref="CheckWireropeDetailRef" v-if="isShowCheckWireropeDetail" @close="isShowCheckWireropeDetail = false"></CheckWireropeDetail>
            <!-- 换绳详情-作废信息 -->
            <ChangeWireropeDetail ref="ChangeWireropeDetailRef" v-if="isShowChangeWireropeDetail" @close="isShowChangeWireropeDetail = false"></ChangeWireropeDetail>
            <!-- 作废管理 -->
            <ZuoFei ref="ZuoFeiRef" v-if="isShowZuoFei" @close="isShowZuoFei = false"></ZuoFei>

            <template #footer>
                <el-button type="primary" :loading="loading" @click="onSave" v-if="!isSee">提交</el-button>
            </template>
        </MyDialog>
    </div>
</template>

<script lang="ts" setup>
import { DatePart } from "@/_gx/TsEnums";
import Enums from "@/gx/Enums";
import Gx from "@/gx/Gx";
import { FormRules } from "element-plus";
import { DialogType } from "@/_gx/TsEnums";
import StockSelect from "@/views/wb/Stock/StockSelect.vue";

// 备绳维保详情
import StockWireropeKeepDetail from "@/views/wb/StockWireropeKeep/StockWireropeKeepDetail.vue";
// 在用绳维保详情
import UsingWireropeKeepDetail from "@/views/wi/UsingWireropeKeep/UsingWireropeKeepDetail.vue";
// 在用绳检测详情
import CheckWireropeDetail from "@/views/wi/CheckWirerope/CheckWireropeDetail.vue";
// 换绳详情-作废信息
import ChangeWireropeDetail from "@/views/wi/ChangeWirerope/ChangeWireropeDetail.vue";
//作废管理
import ZuoFei from "./ZuoFei.vue";

//接收父组件的传值
const usingWireropeID = inject("usingWireropeID") as Ref<number | null>;

//定义当前页面数据对象
const thisData = ref<any>({
    laNiu_FilesList: [],
    qianWuSun_FilesList: [],
    houWuSun_FilesList: [],
});

//安装日期限制
const installDateDisabledDate = (time) => {
    if (time.getTime() > Date.now()) {
        return true;
    } else {
        return false;
    }
};

//查看
const isSee = ref(false);
const isEdit = ref(false);

//loading...
const loading = ref(false);

const HoisterUsageRef = ref(null);
const WireropeTypeRef = ref(null);

const installAddressIDSelect = ref(null);
const hoisterIDSelect = ref(null);

//定义表单验证规则
const rules = ref<FormRules>({
    code: [{ required: true, message: "请输入钢丝绳编码", trigger: "blur" }],
    name: [{ required: true, message: "请输入钢丝绳名称", trigger: "blur" }],
    departmentID: [{ required: true, message: "请选择矿山", trigger: "change" }],
    installAddressID: [{ required: true, message: "请选择安装地点", trigger: "change" }],
    hoisterID: [{ required: true, message: "请选择提升机类型", trigger: "change" }],
    hoisterUsageID: [{ required: true, message: "请选择提升用途", trigger: "change" }],
    wireropeTypeID: [{ required: true, message: "请选择钢丝绳类型", trigger: "change" }],
    installLengthNum: [{ required: true, message: "请填写安装长度", trigger: "blur" }],
    installDate: [{ required: true, message: "请选择安装日期", trigger: "change" }],
    outStockDate: [{ required: true, message: "请选择出库日期", trigger: "change" }],
    nextCheckDate: [{ required: true, message: "请选择下次检测日期", trigger: "change" }],
});

//标题
const title = computed(() => {
    if (Gx.IsEmpty(usingWireropeID.value)) {
        return "在用绳档案详情 - 创建";
    } else {
        return `在用绳档案详情 - 编辑 - ${thisData.value.code}`;
    }
});

//初始化
const Init = async (type) => {
    await installAddressIDSelect.value.GetList();
    await hoisterIDSelect.value.GetList();
    await HoisterUsageRef.value.GetList();
    await WireropeTypeRef.value.GetList();

    if (type == "查看") {
        isSee.value = true;
    }
    if (type == "编辑") {
        isEdit.value = true;
    }
    if (!Gx.IsEmpty(usingWireropeID.value)) {
        await App.CallApi(Api.UsingWirerope.GetByID(usingWireropeID.value), {
            success: (res) => {
                res.billModelList = [];
                res.installModelList = [];
                res.zuoFeiModelList = [];
                if (res.billModel) {
                    res.billModelList.push(res.billModel);
                }

                if (res.installModel) {
                    res.installModelList.push(res.installModel);
                }

                if (res.zuoFeiModel) {
                    res.zuoFeiModelList.push(res.zuoFeiModel);
                }
                thisData.value = res;

                // nextTick(() => {
                //     HoisterUsageRef.value.GetList();
                //     WireropeTypeRef.value.GetList();
                // });
            },
        });
    } else {
        thisData.value.installDate = Gx.FormatDate("YYYY-MM-DD");
        thisData.value.outStockDate = Gx.FormatDate("YYYY-MM-DD");
    }
};

//表单Ref对象
const UsingWireropeDetailFormRef = ref(null);

//保存
const onSave = () => {
    UsingWireropeDetailFormRef.value.validate((isOk: boolean) => {
        if (!isOk) {
            return;
        }

        let _api = null;
        let _data = thisData.value;
        if (Gx.IsEmpty(usingWireropeID.value)) {
            //添加
            _api = Api.UsingWirerope.Insert;
        } else {
            //修改
            _api = Api.UsingWirerope.Update;
        }

        loading.value = true;
        App.CallApi(_api, {
            data: _data,
            success: (res) => {
                emits("close", true);
            },
            complete: () => {
                loading.value = false;
            },
        });
    });
};

//提升机类型选择
const hoisterChange = () => {
    HoisterUsageRef.value.ClearData();
    HoisterUsageRef.value.ClearList();

    WireropeTypeRef.value.ClearData();
    WireropeTypeRef.value.ClearList();

    if (Gx.IsEmpty(thisData.value.hoisterID)) {
        return;
    }

    nextTick(() => {
        HoisterUsageRef.value.GetList();
        WireropeTypeRef.value.GetList();
    });
};

const activeName = ref("入库信息");

/********************************************** 详情 **********************************************/
//备绳维保详情
const isShowStockWireropeKeepDetail = ref(false);
const StockWireropeKeepDetailRef = ref(null);
//在用绳维保详情
const isShowUsingWireropeKeep = ref(false);
const UsingWireropeKeepDetailRef = ref(null);
//在用绳检测详情
const isShowCheckWireropeDetail = ref(false);
const CheckWireropeDetailRef = ref(null);
//换绳详情-作废信息
const isShowChangeWireropeDetail = ref(false);
const ChangeWireropeDetailRef = ref(null);

const isShowZuoFei = ref(false);
const ZuoFeiRef = ref(null);

//向子组件传值
const rowAutoID = ref<number | null>(null);
provide("rowAutoID", rowAutoID);

//显示详情
const onShowDetail = (row, type) => {
    rowAutoID.value = row.autoID;

    switch (type) {
        case "备绳维保":
            isShowStockWireropeKeepDetail.value = true;
            nextTick(() => {
                StockWireropeKeepDetailRef.value.Init(true);
            });
            break;

        case "在用维保":
            isShowUsingWireropeKeep.value = true;
            nextTick(() => {
                UsingWireropeKeepDetailRef.value.Init(true);
            });
            break;

        case "在用检测":
            isShowCheckWireropeDetail.value = true;
            nextTick(() => {
                CheckWireropeDetailRef.value.Init("查看", row.usingWireropeID);
            });
            break;

        case "作废信息":
            isShowChangeWireropeDetail.value = true;
            nextTick(() => {
                ChangeWireropeDetailRef.value.Init("查看");
            });
            break;

        case "作废管理":
            isShowZuoFei.value = true;
            nextTick(() => {
                ZuoFeiRef.value.Init(true);
            });
            break;
    }
};

/********************************************** 钢丝绳选择 **********************************************/
let isShowStockSelect = ref(false);

//打开钢丝绳选择
const onOpenStockSelect = () => {
    if (!isSee.value && !isEdit.value) {
        isShowStockSelect.value = true;
    }
};

//关闭钢丝绳选择
const onCloseStockSelect = (selectData) => {
    isShowStockSelect.value = false;
    if (!Gx.IsEmpty(selectData)) {
        thisData.value.stockID = selectData.stockID;
        thisData.value.code = selectData.code;
        thisData.value.name = selectData.name;
        thisData.value.guiGe = selectData.guiGe;
        thisData.value.diameter = selectData.diameter;
        thisData.value.nianJu = selectData.nianJu;
        thisData.value.lengthNum = selectData.lengthNum;
        thisData.value.cnt = selectData.cnt;
        thisData.value.mpaID = selectData.mpaID;
        thisData.value.mpaName = selectData.mpaName;
        thisData.value.surfaceStatusID = selectData.surfaceStatusID;
        thisData.value.surfaceStatusName = selectData.surfaceStatusName;
        thisData.value.twistingTypeID = selectData.twistingTypeID;
        thisData.value.twistingTypeName = selectData.twistingTypeName;
        thisData.value.departmentID = selectData.departmentID;
        thisData.value.keepDay = selectData.keepDay;
        thisData.value.hoisterID = selectData.hoisterID;
        thisData.value.hoisterName = selectData.hoisterName;
        thisData.value.supplierID = selectData.supplierID;
        thisData.value.supplierName = selectData.supplierName;
        thisData.value.producerID = selectData.producerID;
        thisData.value.producerName = selectData.producerName;
        thisData.value.chuChang_FilesList = selectData.chuChang_FilesList;
        thisData.value.yanShou_FilesList = selectData.yanShou_FilesList;
        thisData.value.jianCe_FilesList = selectData.jianCe_FilesList;
        thisData.value.attr_FilesList = selectData.attr_FilesList;

        HoisterUsageRef.value.ClearData();
        HoisterUsageRef.value.ClearList();

        WireropeTypeRef.value.ClearData();
        WireropeTypeRef.value.ClearList();

        nextTick(async () => {
            if (!Gx.IsEmpty(thisData.value.hoisterID)) {
                await HoisterUsageRef.value.GetList();
                await WireropeTypeRef.value.GetList();

                thisData.value.hoisterUsageID = selectData.hoisterUsageID;
                thisData.value.hoisterUsageName = selectData.hoisterUsageName;
                thisData.value.wireropeTypeID = selectData.wireropeTypeID;
                thisData.value.wireropeTypeName = selectData.wireropeTypeName;
            }
        });

        // thisData.value.billDetailModels[selectIndex.value].remark = selectData.remark;
    }
};

//关闭
const onClose = () => {
    emits("close", false);
};

//向上抛出的事件与方法
const emits = defineEmits(["close"]);
defineExpose({ Init });
</script>
